<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <%@include file="/common/common.jspf"%>

    <style type="text/css">

        table,td {
            text-align: center;
            /*vertical-align:middle;*/
            /*border-style: solid*/
        }
        table,th {
            text-align: center;
            /*vertical-align:middle;*/
            /*border-style: solid*/
        }
    </style>
</head>
<body>
<div class="row">
    <%--<div class="col-xs-1" >--%>

    </div>
    <%--<div class="col-xs-2" >--%>
        <%--<form class="form-inline">--%>

                <%--<div class="form-group" style="width: 160px;">--%>
<ul class="list-inline">
    <li>
        <label class="form-inline">&nbsp;&nbsp;设备名称:</label>
    </li>
    <li>
        <input type="text" class="form-control" name="deviceName" id="deviceName"/>
    </li>
    <li>
        <button type="button" class="btn btn-warning" onclick="querydata()" id="query">查询</button>
    </li>
</ul>
            <%--</div>--%>
        <%--</form>--%>
    <%--</div>--%>
    <%--<div class="col-xs-1" style="position: absolute;left: 250px;">--%>
    </div>
</div>
    <hr>

    <table class="table table-hover">
        <thead>
            <tr>
                <th>设备名称</th>
                <th>设备编码</th>
                <th>设备类别</th>
                <th>设备类别id</th>
                <%--<th>设备规格</th>--%>
            </tr>
        </thead>
        <tbody id="tb1">
        <c:forEach var="d" items="${data}">
            <tr onclick="getData(this)">
                <td>${d.deviceName}</td>
                <td>${d.deviceCode}</td>

                <td>${d.deviceTypeName}</td>
                <td>${d.deviceTypeId}</td>
            </tr>
        </c:forEach>
        </tbody>
    </table>

    <footer class="panel-footer text-right bg-light lter">
        <button id="op_ok" type="submit" class="btn btn-success btn-s-xs">关闭页面</button>
    </footer>

<script type="text/javascript">

    $("#op_ok").click("click", function() {
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
        parent.layer.close(index);
    });

    function getData(data) {
        var tdArr = data.children;//获取点击的行数据

        //查询选中设备关联的部位
        ly.ajax({
            type : "get",
            // data : jsonIndex[0],
            url : rootPath + '/devicefault/getDeviceParts.shtml?id='+ tdArr[3].innerHTML,//参数为设备类型id
            dataType : "json",// 这里的dataType就是返回回来的数据格式了html,xml,json
            async : false,
            cache : false,// 设置是否缓存，默认设置成为true，当需要每次刷新都需要执行数据库操作的话，需要设置成为false
            success : function(data) {
                console.log(data);
                window.parent.inser_datas(tdArr,data);
                // layer.close(layer.index);
                // if("success" == data){
                //     layer.msg("重置成功！");
                // } else {
                //     layer.msg("重置失败！");
                // }
            }
        });


    }

    function querydata(){
        var name = $("#deviceName").val();

        //查询设备
        $.ajax({
            url: rootPath + "/devicefault/getDeviceInfoByName.shtml",
            data: {name:name},
            type: "GET",
            dataType: "json",
            success: function(data) {
                console.log(data);
                var tb1 = document.getElementById("tb1");
                var htmlData = '';
                for(var i = 0; i<data.length; i++){
                    htmlData += '<tr onclick="getData(this)">' +
                                    '<td>' + data[i].deviceName + '</td>' +
                                    '<td>' + data[i].deviceCode + '</td>' +
                                    '<td>' + data[i].deviceTypeName + '</td>' +
                                    '<td>' + data[i].deviceTypeId + '</td>' +
                                '</tr>'
                }
                tb1.innerHTML = htmlData;

            }
        });


    }
</script>
</body>

</html>